<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Dialog | native-ui</title>
  <link rel="stylesheet" href="https://s-mohan.github.io/native-ui/assets/css/style.css?v=580703017e099ee9af4d5a1c875ac8d3896cfe56">
  <link rel="stylesheet" href="./dialog.css">
  <style>
    button {
      display: inline-block;
      padding: 5px 10px;
      line-height: 20px;
      font-family: inherit;
    }
    article > section {
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <section class="page-header">
    <h1 class="project-name">Dialog</h1>
    <h2 class="project-tagline">HTML原生UI组件</h2>
    <a href="https://github.com/S-mohan/native-ui" class="btn">View on GitHub</a>
    <a href="https://s-mohan.github.io/native-ui/dialog/" class="btn">Document</a>
  </section>
  <article class="main-content">
    <section>
      <h3>Default style</h3>
      <button id="toggle-demo1">open dialog</button>
      <dialog style="max-width: 800px;" id="dialog1">
        <p> dialog is an element for a popup box in a web page, including a modal option which will make the rest of the page
          inert during use. This could be useful to block a user's interaction until they give you a response, or to confirm
          an action.
        </p>
        <button class="nui-dialog__btn" data-dismiss="modal" aria-label="Close">Cancel</button>
      </dialog>
    </section>

    <section>
      <h3>Default style</h3>
      <button id="toggle-demo2">open dialog</button>
      <dialog style="max-width: 800px;" id="dialog2">
        <p> dialog is an element for a popup box in a web page, including a modal option which will make the rest of the page
          inert during use. This could be useful to block a user's interaction until they give you a response, or to confirm
          an action.
        </p>
        <button class="nui-dialog__btn" data-dismiss="modal" aria-label="Close">Cancel</button>
      </dialog>
    </section>

    <section>
      <h3>Custom style</h3>
      <button id="toggle-demo3">open dialog</button>
      <dialog class="nui-dialog" id="dialog3">
        <header class="nui-dialog__head">
          <h3 class="nui-dialog__title">Dialog</h3>
          <button type="button" class="nui-dialog__close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </header>
        <div class="nui-dialog__body" style="max-width: 800px;">
          dialog is an element for a popup box in a web page, including a modal option which will make the rest of the page inert during
          use. This could be useful to block a user's interaction until they give you a response, or to confirm an action.
        </div>
        <footer class="nui-dialog__foot">
          <button class="nui-dialog__btn" data-dismiss="modal" aria-label="Close">Cancel</button>
          <button class="nui-dialog__btn btn-confirm">Confirm</button>
        </footer>
      </dialog>
    </section>

    <section>
      <h3>Use animation</h3>
      <button id="toggle-demo4">open dialog</button>
      <dialog class="nui-dialog nui-dialog--animated" id="dialog4">
        <header class="nui-dialog__head">
          <h3 class="nui-dialog__title">Dialog</h3>
          <button type="button" class="nui-dialog__close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </header>
        <div class="nui-dialog__body" style="max-width: 800px;">
          dialog is an element for a popup box in a web page, including a modal option which will make the rest of the page inert during
          use. This could be useful to block a user's interaction until they give you a response, or to confirm an action.
        </div>
        <footer class="nui-dialog__foot">
          <button class="nui-dialog__btn" data-dismiss="modal" aria-label="Close">Cancel</button>
          <button class="nui-dialog__btn btn-confirm">Confirm</button>
        </footer>
      </dialog>
    </section>
  </article>

  <script>
    var $ = function (id) {
      return document.getElementById(id)
    }
    var dialog1 = $('dialog1')
    var dialog2 = $('dialog2')
    var dialog3 = $('dialog3')
    $('toggle-demo1').addEventListener('click', function () {
      dialog1.show()
    })
    $('toggle-demo2').addEventListener('click', function () {
      dialog2.showModal()
    })
    $('toggle-demo3').addEventListener('click', function () {
      dialog3.showModal()
    })
    $('toggle-demo4').addEventListener('click', function () {
      dialog4.showModal()
    })

    dialog3.addEventListener('close', function (event) {
      console.log(event.type) // dialog.close(type?)
    })

    dialog3.addEventListener('cancel', function (event) {
      console.log(event)
    })

    // close
    document.addEventListener('click', function (e) {
      var target = e.target
      var selector = '[data-dismiss="modal"][aria-label="Close"]'
      if (target.matches(selector) || target.closest(selector)) {
        var modal = target.closest('dialog')
        modal && modal.close()
      }
    })

  </script>
</body>
</html>